<?php
$conn = mysql_connect("localhost:3307", "root", "123456") or die("连接失败");
// **********found**********
mysql_select_db("nrce-03", $conn) or die("连接数据库失败");
Mysql_query("SET NAMES 'gb2312'");
$XH = "";
$KCM = "";
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<head><title>查询学生成绩</title>
    <style type="text/css">
        <!--
        .STYLE1 {
            font-size: 18px;
            font-family: "黑体";
        }

        -->
    </style>
</head>
<body bgcolor="D9DFAA">
<div align="center"><font face="幼圆" size="5" color="#008000">
        <b>查询学生成绩</b></font></div>
<br><br>
<form name="frm1" method="post">
    <table width="350" align="center">
        <tr>
            <td><span class="STYLE1">学号:</span></td>
            <td><input type="text" name="XH" size="10"></td>
            <td><span class="STYLE1">课程名称:</span></td>
            <td><input type="text" name="KCM" size="10"></td>
            <td><input type="submit" name="select" value="查询"></td>
        </tr>
    </table>
</form>
<?php
// **********found**********
if (isset($_POST['select'])) {
    $XH = $_POST['XH'];
    $KCM = $_POST['KCM'];
    if (!$XH || !$KCM)
        echo "<script>alert('输入不正确！')</script>;";
    else {
// **********found**********
        $sql = "select 成绩 from 选课 where 学号='".$XH."' and 课程名称='".$KCM."'";
        $result = mysql_query($sql, $conn);
// **********found**********
        // mysql_fetch_row($result)
        // mysql_fetch_assoc($result)
        // mysql_fetch_array($result)
        $row = mysql_fetch_row($result);
//        if (!$row)
//            echo "<script>alert('无成绩记录！')</script>";
    }
}
?>
<br><br>
<table width="600" align="center">
    <tr>
        <td><span class="STYLE1"><?php echo "学号：" . $XH ?></span></td>
        <td><span class="STYLE1"><?php echo "课程名称：" . $KCM ?></span></td>
        <td><span class="STYLE1">成绩：</span></td>
        <td><input type="text" name="CJ" value="<?php echo @$row[0]; ?>"
            <size
            ="10">
    </tr>
</table>
</body>
</html>
